<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>订单列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
</head>
<style type="text/css">
    .layui-inline{}
</style>
<body>
<div id="aaa"></div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">订单列表</div>
                <div class="layui-card-body">
                    <div class="layui-form-item layui-form"> 
                         <div class="layui-inline">
                            <label class="layui-form-label">订单编号</label>
                          <div class="layui-input-block">
                                <select name="order_sn" lay-verify="" lay-search id="orderSn_">
                                    <option value="">请选择</option>
                                    {foreach $res as $k=>$v}
                                    <option value="{$v['order_sn']}">{$v['order_sn']}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>

                     <div class="layui-inline">
                            <label class="layui-form-label">核销码</label>
                            <div class="layui-input-block">
                                <input type="text" name="cancel_code"  id="cancel_code"  placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                         <div class="layui-inline">
                            <label class="layui-form-label">联系人</label>
                            <div class="layui-input-block">
                                <input type="text" name="linkman"  id="linkman"  placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>  
                         <div class="layui-inline">
                            <label class="layui-form-label">手机号</label>
                            <div class="layui-input-block">
                                <input type="text" name="tel"  id="tel"  placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>    
                        <div class="layui-inline">
                            <label class="layui-form-label">下单时间</label>
                            <div class="layui-input-inline" style="width: 190px;">
                                <input type="text" class="layui-input" id="selectdate" readonly="" placeholder="~">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <div class="layui-btn-group test-table-operate-btn">
                                <button class="layui-btn" data-type="searchUserButton">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                </button>
                            </div>
                        </div>

                    </div>
                    <table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate">
                    </table>
                    <script type="text/html" id="test-table-operate-barDemo">
                        <a class="layui-btn layui-btn-xs" lay-event="showDetail">详细信息</a>
                        <a class="layui-btn layui-btn-xs" lay-event="cancelCode">核销</a>
                     </script>
                </div>
            </div>
        </div>
    </div>
</div>
<!--添加弹窗-->
<div id="hotelOrderInfo" style="display: none;padding:20px;">
    <form class="layui-form" action="" lay-filter="component-form-group"> 

        <div class="layui-form-item"> 
            <div class="layui-inline">
                <label class="layui-form-label">订单编号：</label>
                <div class="layui-input-block">
                    <input type="text"  id="order_sn" autocomplete="off" class="layui-input">
                </div>
            </div>
           
            <div class="layui-inline">
                <label class="layui-form-label">支付类型：</label>
                <div class="layui-input-block">
                    <input type="text" id="pay_type" autocomplete="off" class="layui-input">
                </div>
            </div> 
        </div>
      <div class="layui-form-item">  
                <div class="layui-inline">
                <label class="layui-form-label">入住姓名：</label>
                <div class="layui-input-block">
                    <input type="text" id="linkman_" autocomplete="off" class="layui-input">
                </div>
            </div>
              <div class="layui-inline">
                <label class="layui-form-label">入住电话：</label>
                <div class="layui-input-block">
                    <input type="text" id="tel_" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">开始入住：</label>
                <div class="layui-input-block">
                    <input type="text" id="start_time" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">结束入住：</label>
                <div class="layui-input-block">
                    <input type="text" id="end_time" autocomplete="off" class="layui-input">
                </div>
            </div>
            
        </div>

        <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">入住天数：</label>
                <div class="layui-input-block">
                    <input type="text"  id="living_days" autocomplete="off" class="layui-input">
                </div>
            </div>
              <div class="layui-inline">
                <label class="layui-form-label">入住人数：</label>
                <div class="layui-input-block">
                    <input type="text" id="living_peason" autocomplete="off" class="layui-input">
                </div>
            </div>
            
        </div>

        <div class="layui-form-item"> 
           <div class="layui-inline">
                <label class="layui-form-label">实付价格：</label>
                <div class="layui-input-block">
                    <input type="text" id='order_price' autocomplete="off" class="layui-input">
                </div>
            </div> 
            <div class="layui-inline">  
                <label class="layui-form-label">下单时间：</label>
                <div class="layui-input-block">
                   <input type="text" id="create_time" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div> 
            <div class="layui-form-item"> 
           <div class="layui-inline">
                <label class="layui-form-label">预订说明：</label>
                <div class="layui-input-block">
                    <input type="text" id='content' autocomplete="off" class="layui-input">
                </div>
            </div> 
            <div class="layui-inline">
                <label class="layui-form-label">房间类型：</label>
                <div class="layui-input-block">
                   <input type="text" id="room_name" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>  
    </form>
</div>

<!--修改弹窗--> 
 
<script src="/static/layuiadmin/layui/layui.js"></script>
<script>

    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','table','laydate','set'], function(){
        $ = layui.jquery;
        var table = layui.table
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,form = layui.form;

        laydate.render({
            elem: '#selectdate'
            , range: '~'
        });

        table.render({
            elem: '#test-table-operate'
            ,url: "{:url('Order/outinorder')}"
            ,height: 'full-155'
            ,cols: [[
                 {field:'order_sn',align:'center',title: '订单编号'}
                ,{field:'linkman', align:'center', title: '联系人姓名'}
                ,{field:'cancel_code', align:'center', title: '核销码'}
                ,{field:'tel', align:'center', title: '联系人电话'}
                ,{field:'start_time',width:180, align:'center', title: '入住日期'}
                ,{field:'order_status', align:'center', title: '订单状态',templet:function(d){
                    
                    if (d.order_status == 0){
                        return '待付款';
                    }else if(d.order_status == 1){ 
                        if(d.refund_status == 0 ){
                             return '未入住(申请退款中)';
                        }else{
                            return '未入住';
                        }
                       
                    }else if(d.order_status == 2){
                        return '已取消';
                    }else if(d.order_status == 3){
                        return '待评价';
                    }else if(d.order_status == 4){
                        return '已完成';
                    }
                    
                }}
                ,{field:'order_price', align:'center', title: '订单金额'}
                ,{field:'create_time',width:180,align:'center', title: '下单时间'}
                ,{align:'center',width:150, title: '操作', toolbar: '#test-table-operate-barDemo'}
            ]]
            ,page:true
            ,limit:20
        });

        form.render(null,'component-form-group');

        laydate.render({
            elem: '#search_time'
        });

        //监听工具条
        table.on('tool(test-table-operate)', function(obj){
            var data = obj.data;
            if(obj.event === 'showDetail'){ 
                   var loading = layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
                var order_id = data.order_id; 
                $.ajax({
                    url: "{:url('Order/getOrderDetail')}",
                    type: 'post',
                    dataType: 'json',
                    data: {order_id:order_id},
                    success: function(data){
                        layer.close(loading);
                        if (data.code === 0) {
                            console.log(data.data);
                            var obj = data.data;
                            if(obj.order_sn==""){
                                $('#order_sn').val('未设置');
                            }else{
                                $('#order_sn').val(obj.order_sn);
                            }
                             if(obj.pay_type ==""){
                                $('#pay_type').val('未设置');
                            }else{
                                $('#pay_type').val(obj.pay_type);
                            } 
                             $('#pay_type').val(obj.pay_type);
                             $('#linkman_').val(obj.linkman);
                             $('#tel_').val(obj.tel);
                             $('#start_time').val(obj.start_time);
                             $('#end_time').val(obj.end_time);
                             $('#living_peason').val(obj.living_peason);
                             $('#living_days').val(obj.living_days);
                             $('#order_price').val(obj.order_price);
                             $('#create_time').val(obj.create_time);
                             $('#content').val(obj.content);
                             $('#room_name').val(obj.room_name);
                            var userDetailModal = layer.open({
                                title:'待核销订单详情'
                                ,type: 1
                                ,shadeClose: true
                                ,area:['800px']
                                ,content: $('#hotelOrderInfo')
                            });
                        }else{
                            layer.msg('获取信息失败',{icon:2,time:1000});
                        }


                    }
                })

            }else if(obj.event === 'cancelCode'){ 
                 layer.confirm('确认核销'+data.order_sn+'该订单吗？', {
                      btn: ['确定','取消'] //按钮
                    }, function(){
                        
                   var order_id = data.order_id; 
                   var room_id = data.room_id;   
                   $("#order_sn_").val(data.order_sn); 
                $.ajax({
                    url: "{:url('Order/cancelCode')}",
                    type: 'post',
                    dataType: 'json', 
                    data: {order_sn:data.order_sn},
                    success: function(data){
                        layer.close(loading);
                        if (data.code === 1) {
                            layer.msg('核销成功', {icon: 1, time: 2000}, function () {
                            window.location.reload();
                        });

                        }else{
                            layer.msg('核销失败',{icon:2,time:1000});
                        }


                    }
                })  

                    }, function(){layer.closeAll();
                    });  
            }else if(obj.event === 'submit'){  

            }


        });
      //添加提交
        form.on('submit(nowsubmit)', function (data) { 
            var loading = layer.load(1, {
                shade: [0.1, '#fff'] //0.1透明度的白色背景
            });
            var room_number =  $("#room_number").val(); 
            $.ajax({
                url: "{:url('Order/cancelCode')}",
                type: 'post',
                dataType: 'json',
                data: {data:data.field},
                success: function (data) { 
                    layer.close(loading);
                    if (data.code === 1) {
                        layer.msg('核销成功', {icon: 1, time: 2000}, function () {
                            window.location.reload();
                        });
                    } else {
                        layer.msg('核销失败', {icon: 2, time: 1000});
                    }
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });


        var $ = layui.$, active = {
            addadmin: function() {
                window.location.href="{:url('Merchant/guideAdd')}";
            },
            searchUserButton:function(){
                var order_sn     = $('#orderSn_').val();
                var order_status = $("#order_status_").val();
                var selectdate   = $("#selectdate").val();
                var cancel_code   = $("#cancel_code").val();
                var linkman   = $("#linkman").val();
                var tel   = $("#tel").val();
                table.reload('test-table-operate', {
                    where: {
                        order_sn:order_sn,
                        order_status:order_status,
                        selectdate:selectdate,
                        cancel_code:cancel_code,
                        linkman:linkman,
                        tel:tel
                    }
                    ,page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
            }
        };
        //绑定点击事件
        $('.test-table-operate-btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });

    //格式化时间函数
    function Format(datetime,fmt) {
        if (parseInt(datetime)==datetime) {
            if (datetime.length==10) {
                datetime=parseInt(datetime)*1000;
            } else if(datetime.length==13) {
                datetime=parseInt(datetime);
            }
        }
        datetime=new Date(datetime);
        var o = {
            "M+" : datetime.getMonth()+1,                 //月份
            "d+" : datetime.getDate(),                    //日
            "h+" : datetime.getHours(),                   //小时
            "m+" : datetime.getMinutes(),                 //分
            "s+" : datetime.getSeconds(),                 //秒
            "q+" : Math.floor((datetime.getMonth()+3)/3), //季度
            "S"  : datetime.getMilliseconds()             //毫秒
        };
        if(/(y+)/.test(fmt))
            fmt=fmt.replace(RegExp.$1, (datetime.getFullYear()+"").substr(4 - RegExp.$1.length));
        for(var k in o)
            if(new RegExp("("+ k +")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
        return fmt;
    }

</script>


</body>
</html>